import * as THREE from 'three';
import Scene from './Scene';
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls';

export default class Camera{
    constructor(){
        this.scene = new Scene();
        this.sizes = this.scene.sizes;
        this.canvasScene = this.scene.scene;
        this.canvas = this.scene.canvas;
        this.createPerspectiveCamera();
        this.createOrthographicCamera();
        // this.createPerspectiveCamera2();
        this.setOrbitControls();
    }
    createPerspectiveCamera(){
        this.perspectiveCamera = new THREE.PerspectiveCamera(
            35,
            this.sizes.aspect,
            0.1,
            1000
        );
        this.perspectiveCamera.position.set(0, 15, 25);
        this.canvasScene.add(this.perspectiveCamera);
    }
    createPerspectiveCamera2(){
        this.perspectiveCamera2 = new THREE.PerspectiveCamera(
            35,
            this.sizes.aspect,
            0.1,
            1000
        );
        this.perspectiveCamera2.position.set(10, 10, 10);
        this.perspectiveCamera2.lookAt(0, 0, 0);
        // this.canvasScene.add(this.perspectiveCamera2);
        // this.canvasScene.add(new THREE.CameraHelper(this.perspectiveCamera2));
    }
    createOrthographicCamera(){
        // 最终渲染在窗口是根据NDC坐标系，而NDC坐标系与webgl坐标系相反，
        this.orthographicCamera = new THREE.OrthographicCamera(
            (-this.sizes.aspect * this.sizes.frustrum) / 2,
            (this.sizes.aspect * this.sizes.frustrum) / 2,
            this.sizes.frustrum / 2,
            -this.sizes.frustrum / 2,
            -30,
            30
        );
        // this.canvasScene.add(new THREE.CameraHelper(this.orthographicCamera));
        // this.canvasScene.add(this.orthographicCamera);
    }
    setOrbitControls(){
        this.controls = new OrbitControls(this.perspectiveCamera, this.canvas);
        // this.controls.enableDamping = true;
        this.controls.enableZoom = true;
    }
    resize(){
        // 更新透视相机的视图矩阵
        this.perspectiveCamera.aspect = this.sizes.aspect;
        this.perspectiveCamera.updateProjectionMatrix();
        // 更新正交相机的视图矩阵
        
        // this.handleClick = function(){
        //     console.log(perspection.size. )
        // }        
    }
}